package com.sys.controller;

import com.sys.service.SysLogService;
import com.sys.utils.Utils;
import com.bhudy.base.QueryFilter;
import com.bhudy.enums.Relation;
import com.bhudy.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author bhudy
 * @Description SysLogController
 * @Date Wed Nov 13 17:45:49 CST 2019
 */
@RestController
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;

    /**
     * 获取操作日志的的数据
     *
     * @param page  页数{1}
     * @param limit 显示数量{10}
     * @return sysLog的list
     */
    @GetMapping(value = "/api/v1/sysLogs")
    public ResponseResult getAll(Integer page, Integer limit, String requestUrl, Integer logType, String logTitle, String createByName, String createDate) {
        QueryFilter queryFilter = new QueryFilter();
        if (page == null) page = 1;
        if (limit == null) limit = 10;
        if (requestUrl != null && !requestUrl.equals("")) {
            queryFilter.andLike("requestUrl", "%" + requestUrl + "%");
        }
        if (logType != null) {
            queryFilter.and("logType", logType);
        }
        if (logTitle != null && !logTitle.equals("")) {
            queryFilter.andLike("logTitle", "%" + logTitle + "%");
        }
        if (createByName != null && !createByName.equals("")) {
            queryFilter.andLike("createByName", "%" + createByName + "%");
        }
        if (createDate != null && !createDate.equals("")) {
            queryFilter.and("createDate", Relation.BETWEEN, Utils.formatDate(Utils.formatLong(createDate.split(",")[0])),
                    Utils.formatDate(Utils.formatLong(createDate.split(",")[1])));
        }
        queryFilter.limit(--page, limit);
        return ResponseResult.printMapJson(0, sysLogService.count(queryFilter), sysLogService.findList(queryFilter));
    }

    @GetMapping(value = "/api/v1/sysLog")
    public ResponseResult get(Long id) {
        return ResponseResult.printMapJson(0, sysLogService.get(id));
    }

    /*@PostMapping(value = "/api/v1/sysLog")
    public ResponseResult insert(@RequestBody String json) {
        return ResponseResult.printMapJson(0, sysLogService.insert(JSONObject.parseObject(json, SysLog.class)));
    }

    @PutMapping(value = "/api/v1/sysLog")
    public ResponseResult update(@RequestBody String json) {
        return ResponseResult.printMapJson(0, sysLogService.update(JSONObject.parseObject(json, SysLog.class)));
    }

    @DeleteMapping(value = "/api/v1/sysLogs")
    public ResponseResult delete(@RequestBody String json) {
        return ResponseResult.printMapJson(0, sysLogService.delete(JSONObject.parseObject(json, Long[].class)));
    }*/

}
